package com.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.sfzy.entity.ClassQaAnswer;
import com.sfzy.entity.ClassQaQuestion;
import com.sfzy.service.ClassQaAnswerService;
import com.sfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("classQaAnswer")
public class ClassQaAnswerController {
    @Autowired
    private ClassQaAnswerService classQaAnswerService;

    //增
    @PostMapping
    public R add(@RequestBody ClassQaAnswer classQaAnswer) {
        int i = classQaAnswerService.addClassQaAnswer(classQaAnswer);
        if(i!=0){
            return R.ok();
        }
        return R.fail();
    }
    //改
    @PutMapping
    public R update(@RequestBody ClassQaAnswer classQaAnswer) {
        int i = classQaAnswerService.updateClassQaAnswer(classQaAnswer);
        if(i!=0){
            return R.ok();
        }
        return R.fail();
    }
    //删
    @DeleteMapping("{id}")
    public R delete(@PathVariable("id") int id){
        int i = classQaAnswerService.deleteClassQaAnswer(id);
        if(i!=0){
            return R.ok();
        }
        return R.fail();
    }

    //id查
    @GetMapping("{id}")
    public R selectById(@PathVariable("id") int id){
        ClassQaAnswer answer = classQaAnswerService.getById(id);
        return R.ok(answer);


    }
    //分页
    @GetMapping("page")
    public R getByPage(ClassQaAnswer classQaAnswer,
                       @RequestParam(required = false,defaultValue = "1") int pageNum,
                       @RequestParam(required = false,defaultValue = "5") int pageSize){
        PageInfo<ClassQaAnswer> page = classQaAnswerService.getByPage(classQaAnswer, pageNum, pageSize);
        return R.ok(page);
    }
    @GetMapping()
    public R selectByIds(int id){
        ClassQaAnswer answer = classQaAnswerService.getById(id);
        return R.ok(answer);


    }
}
